# -*- coding: utf-8 -*-
# @author: wch
# @file: trackBar.py
# @time: 2023/2/3 14:16

# createTrackBar 控件
# getTrackbarPos

# createTrackBar参数
# trackbarname,winname
# value:trackbar 当前值
# count：最小值为0，最大值count
# callback，userdata


# getTrackBarPos
# trackbarname
# winname
# 输出：当前值

import cv2
import numpy_learn as np

def callback(userdata=None):
    pass

cv2.namedWindow("trackbar", cv2.WINDOW_NORMAL)

# 创建trackbar
cv2.createTrackbar("R", "trackbar", 0, 255, callback)
cv2.createTrackbar("G", "trackbar", 0, 255, callback)
cv2.createTrackbar("B", "trackbar", 0, 255, callback)

img = np.zeros((10, 10, 3), dtype=np.uint8)
# img[:] =[1,1,1]
# print(img)

while True:

    r = cv2.getTrackbarPos("R", "trackbar")
    g = cv2.getTrackbarPos("G", "trackbar")
    b = cv2.getTrackbarPos("B", "trackbar")
    img[:] = [r, g, b]
    cv2.imshow("trackbar", img)
    key = cv2.waitKey(10)
    if key & 0xFF == ord("q"):
        break
cv2.destroyAllWindows()

